package com.i2works.smartluolong.web.config;


import com.i2works.smartluolong.utils.config.DruidConfigurationUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * druid配置
 *
 * @author Liu Yutao <koal@vip.qq.com>
 * @date 2017/12/14 9:34
 */
@Configuration
public class DruidConfiguration {

    /**
     * 访问路径（域名+loginPath）
     */
    @Value("${druid.login.path}")
    private String loginPath;
    /**
     * 登录账号
     */
    @Value("${druid.login.username}")
    private String loginUsername;
    /**
     * 登录密码
     */
    @Value("${druid.login.password}")
    private String loginPassword;


    /**
     * 注册
     *
     * @param loginPath     登录地址
     * @param loginUsername 登录用户名
     * @param loginPassword 登录密码
     */
    @Bean
    public ServletRegistrationBean druidServlet() {
        return DruidConfigurationUtils.druidServlet(loginPath, loginUsername, loginPassword);
    }

    /**
     * 拦截规则
     *
     * @param loginPath 登录地址
     */
    @Bean
    public FilterRegistrationBean filterRegistrationBean() {
        return DruidConfigurationUtils.filter(loginPath);
    }


}
